import request, { extend } from 'umi-request';
import {message} from 'antd'
import {singleType} from '../data.d'
const errorHandler = function(error:any) {
    if (error.response) {
      if(error.response.status>=500){
          message.error('服务器出错')
        }else if(error.response.status>=400){
          message.error('请求出错')
      }
    } else {
        message.error('网络出错啦')
    }
  throw error
  };
  
  const extendRequest = extend({errorHandler,timeout:5000});
  
export const getUserList = async () => {
    const data = await extendRequest('/api/user', {
        method: 'get'
    }).then(function(response) {
        return response
    }).catch(function(error) {
        return error
    })
    
    return data
}
export const editUserList = async (params:{id:number,values:singleType}) => {
    
    const data = await extendRequest('/api/user', {
        method: 'post',
        requestType:'form',
        data:params
    }).then(function(response) {
        return response
    }).catch(function(error) {
        
        return error
    })
    
    return data
}
export const delUserList = async (params:{id:number}) => {
    console.log(params);
    
    const data = await extendRequest('/api/user', {
        method: 'delete',
        params
    }).then(function(response) {
        return response
    }).catch(function(error) {
        return error
    })
    return data
}
export const addUserList = async (params:singleType) => {
    const data = await extendRequest('/api/user', {
        method: 'put',
        data:params,
        requestType:'form'
    }).then(function(response) {
        return response
    }).catch(function(error) {
         return error
    })
    return data
}